Sub data_copy()

' --------------------定义变量开始-------------------

    Dim source_work_book As Workbook
    Dim target_work_book As Workbook
    Dim source_work_sheet As Worksheet
    Dim target_work_sheet As Worksheet
    Dim source_range As Range
    Dim target_range As Range

' --------------------定义变量结束-------------------

' --------------------用户自定义初始变量赋值开始-------------------

    ' 源sheet页索引
    source_sheet_index = 1
    ' 目标sheet页索引
    target_sheet_index = 1
    ' 文件输入位置坐标
    input_file_index = "F1"
    ' 基础文件路径
    base_url = "D:/"
    ' 读取的单元格范围
    source_range_index = "A1:AB100000"
    ' 写入的的起始单元格
    target_range_index = "A1"
    ' 写入的单元格偏移行数
    target_range_offset = 2 

' --------------------用户自定义初始变量赋值结束-------------------

    ' 选中目标sheet页
    Sheets(target_sheet_index).Select
    ' 清除历史数据
    ActiveSheet.UsedRange.EntireRow.Offset(target_range_offset).Delete
    ' 读取文件名
    file_name = Range(input_file_index).Value
    ' 拼接文件全路径
    full_file_name = base_url + file_name
    ' 设置源工作簿和目标工作簿
    Set source_work_book = Workbooks.Open(full_file_name)
    Set target_work_book = ThisWorkbook
    ' 设置源和目标sheet页
    Set source_work_sheet = source_work_book.Worksheets(source_sheet_index)
    Set target_work_sheet = target_work_book.Worksheets(target_sheet_index)
    ' 设置源和目标单元格范围
    Set source_range = source_work_sheet.Range(source_range_index)
    Set target_range = target_work_sheet.Range(target_range_index).Offset(target_range_offset, 0)
    ' 复制和粘贴数据
    source_range.Copy target_range
    ' 关闭文件
    source_work_book.Close

' --------------------清除对象引用开始-------------------

    Set source_range = Nothing
    Set target_range = Nothing
    Set source_work_sheet = Nothing
    Set target_work_sheet = Nothing
    Set source_work_book = Nothing
    Set target_work_book = Nothing

' --------------------清除对象引用结束-------------------

End Sub
